package com.sunop.userservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunop.userservice.model.User;
import com.sunop.userservice.model.UserBaseDTO;
import com.sunop.userservice.model.UserRegisterDto;
import com.sunop.userservice.model.UserUpdateInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @since 2025-03-12
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select id from user where name = #{username} and password = #{password}")
    Integer selectByNameAndPassword(String username, String password);

    @Insert("insert into user (name, password, email) values (#{username}, #{password}, #{email})")
    boolean insertuser(UserRegisterDto userRegisterDto);

    @Insert("insert into role (role) values (#{role})")
    boolean insertrole(int role);

    Integer selectRoleById(int id);

    @Select("select u.id as uid, u.name as author, u.avatar ,r.role from user u inner join role r on r.id=u.id where u.id = #{uid}")
    UserBaseDTO getUserBaseDTO(int uid);

    @Select("select avatar from user where id = #{uid}")
    String getFilePath(int uid);

    @Update("update user set avatar = #{path} where id = #{loginIdAsInt}")
    void updateAvatar(String path, int loginIdAsInt);

    void updateUserInfo(UserUpdateInfo userUpdateInfo, int uid);


    void updateRoleInfo(String number,int uid);

    @Select("select class_id from  user where id=#{Id}")
    int getclassId(int Id);

    List<Integer> getUserOverProblemIds(int loginIdAsInt);
}
